package com.apes.fn.fico.reimbursement.model;

import com.apes.fico.masterdata.gl.model.AccountingChart;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.finance.model.BankAccount;
import com.apes.scm.masterdata.frame.model.DutyCenter;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 费用借支明细表
 * Created by lishikun on 2021/1/26 18:22
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ExpenseDebitItem.CONST_TABLE_NAME)
public class ExpenseDebitItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "fn_expense_debit_item";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "费用借支明细表", padding = 8)
    @Comment("费用借支明细编码")
    private String id;

    @Comment("备注")
    @Column(name = "remark", length = 400)
    private String remark;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cost_center_id", referencedColumnName = "id")
    @Comment("成本中心")
    private DutyCenter dutyCenter;

    @Comment("费用金额")
    @Column(name = "expense_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double expenseAmount = 0;

    @Comment("还款金额")
    @Column(name = "repayment_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double repaymentAmount = 0;

    @Comment("还款冻结金额")
    @Column(name = "freeze_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double freezeAmount = 0;


    @Column(name = "cancel_amount", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("取消借支金额")
    private double cancelAmount = 0;

    @ManyToOne(optional = false)
    @JoinColumn(name = "expense_debit_id", referencedColumnName = "id")
    @Comment("费用借支")
    private ExpenseDebit expenseDebit;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fee_type_id", referencedColumnName = "id")
    @Comment("费用类型")
    private FeeType feeType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "subject_name_id", referencedColumnName = "id")
    @Comment("科目名称")
    private AccountingChart accountingChart;

    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Comment("附件")
    @Column(name = "attachment", columnDefinition = "CLOB")
    private String mapAddress;

    @Comment("公司账户")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "bankAccount_id", referencedColumnName = "id")
    private BankAccount bankAccount;

    @Comment("账户名称")
    @Column(name = "account_name")
    private String accountName;

    @Comment("账号")
    @Column(name = "account_number")
    private String accountNumber;

    @Comment("开户行")
    @Column(name = "account_bank")
    private String accountBank;

    @Comment("支行")
    @Column(name = "subbranch", length = 200)
    private String subbranch;

}
